﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using Arles.src.controller;
using Arles.src.utils;

namespace Arles.src.view.controls
{
    public class GListBox : ListBox
    {
        private ImageList imageList;

        public ImageList ImageList
        {
            get { return ImageList; }
            set { imageList = value; }
        }

        public GListBox()
        {
            ItemHeight = 16;
            DrawMode = DrawMode.OwnerDrawFixed;
        }

        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();
            GListBoxItem item;
            Rectangle bounds = e.Bounds;
            Size imageSize = imageList.ImageSize;
            Color color;

            try
            {
                item = (GListBoxItem)Items[e.Index];

                if (item.UndoItem)
                    color = e.ForeColor;
                else
                    color = Color.Gray;

                imageList.Draw(e.Graphics, bounds.Left, bounds.Top, item.ImageIndex);
                e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(color),
                    bounds.Left + imageSize.Width + 4, bounds.Top);
            }
            catch
            {
                LogFactory.Instance.Write("Error: en OnDrawItem de GListBox");
            }

            base.OnDrawItem(e);
        }
    }
}
